/**
 * 
 */
package com.aq.actions;

/**
 * @author shl
 *
 */
import java.util.Collection;

import org.apache.commons.lang.StringUtils;

import com.aq.model.AqNews;
import com.aq.model.AqProduct;
import com.aq.service.IProductService;
import com.hs.common.page.PageParam;
import com.hs.common.page.PageUtil;
import com.hs.core.action.AbstractAction;

public class ProductAction extends AbstractAction {
    
    private IProductService productService;  
    private AqProduct product; 
    
    protected Collection availableItems;
    protected String content;
    protected String pageStr; 
    protected PageUtil pageUtil;  
    protected Long productid;
    
    public String list() throws Exception {
    	
    	PageParam pageParam = new PageParam(this.getHttpServletRequest(),"listproduct.action");
		String hql = " from AqProduct where 1=1";
		pageParam.setSearchSql(hql);
		pageUtil = productService.getProductList(pageParam);
		availableItems = pageUtil.getPageList();
		pageStr = pageUtil.getPageStr(); 
		this.getHttpServletRequest().setAttribute("dataList", availableItems);
        return SUCCESS;         
    }
    
    public String load() throws Exception {
    	String productid = this.getHttpServletRequest().getParameter("productid");
    	if(StringUtils.isNotEmpty(productid)){
    		System.out.println("productid:" + productid);
    		setProductid(new Long(productid));
    		this.product = (AqProduct)productService.findByID(AqProduct.class, this.getProductid());
    		System.out.println(this.product.getMemo()+"asfasdf" + (this.product.getMemo()==null));
    		setContent(this.product.getMemo() == null?" ":this.product.getMemo());
    		 
    	} 
    	
        return SUCCESS;
    }
    
    public String save() throws Exception { 
    	 
    	if(null != product){ 
    		productService.saveObject(product); 
    	}
        return SUCCESS;
    }
    
    public String delete() throws Exception {
       
        return SUCCESS;
    }     
    public Collection getAvailableItems() {
        return availableItems;
    }

	public IProductService getProductService() {
		return productService;
	}

	public void setProductService(IProductService productService) {
		this.productService = productService;
	}

	public AqProduct getProduct() {
		return product;
	}

	public void setProduct(AqProduct product) {
		this.product = product;
	}

	public String getPageStr() {
		return pageStr;
	}

	public void setPageStr(String pageStr) {
		this.pageStr = pageStr;
	}

	public PageUtil getPageUtil() {
		return pageUtil;
	}

	public void setPageUtil(PageUtil pageUtil) {
		this.pageUtil = pageUtil;
	}

	public Long getProductid() {
		return productid;
	}

	public void setProductid(Long productid) {
		this.productid = productid;
	}

	public void setAvailableItems(Collection availableItems) {
		this.availableItems = availableItems;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}
    
}
